//
//  ZSLiveCollectionViewController.m
//  ZSMiao
//
//  Created by zsj1992 on 16/12/2.
//  Copyright © 2016年 bjhj. All rights reserved.
//

#import "ZSLiveCollectionViewController.h"
#import "ZSLiveCollectionViewCell.h"
#import <MJRefresh.h>
#import "ZSRefreshGifHeader.h"
@interface ZSLiveCollectionViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>

@property (weak, nonatomic) IBOutlet UICollectionViewFlowLayout *flowlayout;

@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;

@end

@implementation ZSLiveCollectionViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.flowlayout.itemSize = CGSizeMake(SCREEN_W, SCREEN_H-64);
    self.flowlayout.minimumLineSpacing = 0;
    self.flowlayout.minimumInteritemSpacing = 0;
    
    UINib * nib = [UINib nibWithNibName:@"ZSLiveCollectionViewCell" bundle:[NSBundle mainBundle]];
    [self.collectionView registerNib:nib forCellWithReuseIdentifier:@"liveCell"];

    self.collectionView.pagingEnabled = YES;

    self.collectionView.mj_header = [ZSRefreshGifHeader headerWithRefreshingBlock:^{
        [self changeAnchor];
    }];
}


-(void)changeAnchor{

    
    [self.collectionView.mj_header endRefreshing];
    
    if (self.currentIdx<self.lives.count-1) {
        
        self.currentIdx+=1;
        
    }else{
    
        self.currentIdx=0;
    }
    
    [self.collectionView reloadData];
}


//static NSInteger orginIdx;



-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{

    return 1;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

    ZSLiveCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"liveCell" forIndexPath:indexPath];
    
    ZSLive * live = self.lives[self.currentIdx];
    
    cell.live = live;

    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];


    
    
    
}



@end
